home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Pascal / Code Resources / Ingis WDEF 1.3 / Demo ƒ / Globals ƒ / CustomStubs.p next >
Text File  |  1997-05-09  |  8KB  |  196 lines

  1. { *** DEMO FOR the IngisWDEF WDEF building package *** }
  2.  
  3. {© 1997 by Ingemar Ragnemalm}
  4. {You may use it freely as long as credits are given in the final program.}
  5.  
  6.  
  7. {This is a variation on the "Simple" demo that uses two "cicn" resources for}
  8. {drawing the close box, and two "PICT" resources for drawing the drag bar,}
  9. {in order to demonstrate how you may add your own global variables in the}
  10. {new record MyDataRecord. It uses the demo "OneEvents" instead of Skel,}
  11. {in order to support the close box. The icons were taken from the WDEF demo}
  12. {in the Mac Pascal programming book (available on the net).}
  13.  
  14.  
  15. {This unit holds all custom code}
  16.  
  17. unit CustomStubs;
  18.  
  19. interface
  20.     uses
  21. {$IFC UNDEFINED THINK_PASCAL}
  22.         Types, QuickDraw, ToolUtils, Windows, Events, OSUtils, Icons, Resources,
  23. {$ENDC}
  24.         IngisWDEFUtils;
  25.  
  26.     procedure GetGrowRgn (varCode: integer; macWindow: WindowPeek; var growRgn: RgnHandle);
  27.     procedure GetCloseBox (varCode: integer; dragBar: RgnHandle; var closeBox: Rect);
  28.     procedure GetZoomBox (varCode: integer; dragBar: RgnHandle; var zoomBox: Rect);
  29.     procedure DrawCloseBox (varCode: integer; macWindow: WindowPeek; closeBox: Rect; colorFlag: Boolean);
  30.     procedure DrawZoomBox (varCode: integer; macWindow: WindowPeek; zoomBox: Rect; colorFlag: Boolean);
  31.     procedure DrawHitCloseBox (varCode: integer; macWindow: WindowPeek; closeBox: Rect; colorFlag: Boolean);
  32.     procedure DrawHitZoomBox (varCode: integer; macWindow: WindowPeek; zoomBox: Rect; colorFlag: Boolean);
  33.     procedure DrawDragBar (varCode: integer; macWindow: WindowPeek; dragBar: RgnHandle; colorFlag: Boolean);
  34.     procedure BuildCustomRegions (varCode: integer; theRect: Rect; contRgn, dragRgn: RgnHandle);
  35.     procedure DrawScrollFrame (varCode: integer; macWindow: WindowPeek; theRect: Rect);
  36.     procedure DrawTheGrowIcon (varCode: integer; macWindow: WindowPeek; theRect: Rect; growRgn: RgnHandle; colorFlag: Boolean);
  37.     procedure InitMyWindow (varCode: integer; macWindow: WindowPeek);
  38.     procedure DisposeMyWindow (varCode: integer; macWindow: WindowPeek);
  39.  
  40. {** Constants **}
  41.     const
  42.         kFrameWidth = 1;        { Thickness of frame around window. 1 is normal.}
  43.         kShadowLength = 1;        { Size of drop shadow. 1 is normal.}
  44.         kMinDepthForColor = 4;    { Smallest pixel size for color. 8 (256 colors) is normal. }
  45.         kMinWidth = 100;        { Limits for the dragging rectangle? }
  46.         kMinHeight = 100;
  47.  
  48.     type
  49.         MyDataRecord = record
  50.                 theWindowState: WStateData;
  51. {Insert any globals you need here!}
  52.                 theCloseBoxCicn, theHitCloseBoxCicn: CIconHandle;
  53.                 theDragPict, theInactiveDragPict: PicHandle;
  54.             end;
  55.         MyDataPtr = ^MyDataRecord;
  56.         MyDataHandle = ^MyDataPtr;
  57.  
  58. implementation
  59.  
  60. {*****************************************************************************}
  61. { GetGrowRgn}
  62. {        Return the region with the grow icon, if any.}
  63. { *****************************************************************************}
  64.  
  65.     procedure GetGrowRgn (varCode: integer; macWindow: WindowPeek; var growRgn: RgnHandle);
  66.     begin
  67. {We don't support resizing}
  68.     end;
  69.  
  70. {*****************************************************************************}
  71. { GetCloseBox}
  72. {        Pass back a rectangle which encloses the close box of the window}
  73. { *****************************************************************************}
  74.  
  75.     procedure GetCloseBox (varCode: integer; dragBar: RgnHandle; var closeBox: Rect);
  76.     begin
  77.         with dragBar^^.rgnBBox do
  78.             SetRect(closeBox, left + 5, top + 3, left + 5 + (bottom - top - 4) - 2, bottom - 3);
  79.     end;
  80.  
  81.     procedure GetZoomBox (varCode: integer; dragBar: RgnHandle; var zoomBox: Rect);
  82.     begin
  83. {No zoom box}
  84.     end;
  85.  
  86. {*****************************************************************************}
  87. { Draw close box and zoom box, in normal and hit state }
  88. {        Draw the close box in "hit" state. This can be as simple as an InvertRect. }
  89. { *****************************************************************************}
  90.  
  91.     procedure DrawCloseBox (varCode: integer; macWindow: WindowPeek; closeBox: Rect; colorFlag: Boolean);
  92.     begin
  93.         if colorFlag then
  94.             PlotCIcon(closeBox, MyDataHandle(macWindow^.dataHandle)^^.theCloseBoxCicn)
  95.         else
  96.             StdCloseBox(closeBox, colorFlag);
  97.     end; {}
  98.     procedure DrawZoomBox (varCode: integer; macWindow: WindowPeek; zoomBox: Rect; colorFlag: Boolean);
  99.     begin
  100. {No zoom box}
  101.     end; {}
  102.     procedure DrawHitCloseBox (varCode: integer; macWindow: WindowPeek; closeBox: Rect; colorFlag: Boolean);
  103.     begin
  104.         if colorFlag then
  105.             PlotCIcon(closeBox, MyDataHandle(macWindow^.dataHandle)^^.theHitCloseBoxCicn)
  106.         else
  107.             DrawStdCloseHit(closeBox);
  108.     end; {}
  109.     procedure DrawHitZoomBox (varCode: integer; macWindow: WindowPeek; zoomBox: Rect; colorFlag: Boolean);
  110.     begin
  111.     end; {}
  112.  
  113. {*****************************************************************************}
  114. { DrawDragBar, BW and Color version}
  115. {        Draw the drag bar (not close box/zoom box)}
  116. { *****************************************************************************}
  117.  
  118.     procedure DrawDragBar (varCode: integer; macWindow: WindowPeek; dragBar: RgnHandle; colorFlag: Boolean);
  119.     begin
  120.         if macWindow^.hilited then
  121.             DrawPicture(MyDataHandle(macWindow^.dataHandle)^^.theDragPict, dragBar^^.rgnBBox)
  122.         else
  123.             DrawPicture(MyDataHandle(macWindow^.dataHandle)^^.theInactiveDragPict, dragBar^^.rgnBBox);
  124.     end; {DrawDragBar}
  125.  
  126. {*****************************************************************************}
  127. { BuildCustomRegions}
  128. {        Build the contents region and the drag bar region}
  129. { *****************************************************************************}
  130.  
  131.     procedure BuildCustomRegions (varCode: integer; theRect: Rect; contRgn, dragRgn: RgnHandle);
  132.         var
  133.             tmpRect: Rect;
  134.     begin
  135.         OpenRgn;
  136.         FrameRoundRect(theRect, 10, 10);
  137.         CloseRgn(contRgn);
  138.  
  139.         tmpRect := theRect;
  140.         InsetRect(tmpRect, 15, 0);
  141.         OffsetRect(tmpRect, 0, -18);
  142.         OpenRgn;
  143.         FrameRoundRect(tmpRect, 10, 10);
  144.         CloseRgn(dragRgn);
  145.     end; {BuildCustomRegions}
  146.  
  147. {*****************************************************************************}
  148. { DrawScrollFrame}
  149. {        Draw the scroll frame, if any (used both when resizing and when drawing the grow icon) }
  150. { *****************************************************************************}
  151.  
  152.     procedure DrawScrollFrame (varCode: integer; macWindow: WindowPeek; theRect: Rect);
  153.     begin
  154. {No scroll frame - no resizing}
  155.     end; {DrawScrollFrame}
  156.  
  157. {*****************************************************************************}
  158. { DrawTheGrowIcon, BW and Color version}
  159. {        Draw the grow icon, if any }
  160. { *****************************************************************************}
  161.  
  162.     procedure DrawTheGrowIcon (varCode: integer; macWindow: WindowPeek; theRect: Rect; growRgn: RgnHandle; colorFlag: Boolean);
  163.     begin
  164. {No grow}
  165.     end; {DrawTheGrowIcon}
  166.  
  167. {*****************************************************************************}
  168. { InitMyWindow and DisposeMyWindow }
  169. {        Can often be empty. Set the spareFlag in InitMyWindow if the variant should have a zoom box. }
  170. {        InitMyWindow may initialize any globals in MyDataHandle(macWindow^.dataHandle). }
  171. {        DisposeMyWindow must restore/dispose fields in MyDataHandle(macWindow^.dataHandle) as needed. }
  172. { *****************************************************************************}
  173.  
  174.     procedure InitMyWindow (varCode: integer; macWindow: WindowPeek);
  175.     begin
  176. {No zoom}
  177.         if HasCQDraw then
  178.             begin
  179.                 MyDataHandle(macWindow^.dataHandle)^^.theCloseBoxCicn := GetCIcon(128);
  180.                 MyDataHandle(macWindow^.dataHandle)^^.theHitCloseBoxCicn := GetCIcon(129);
  181.             end;
  182.         MyDataHandle(macWindow^.dataHandle)^^.theDragPict := GetPicture(128);
  183.         MyDataHandle(macWindow^.dataHandle)^^.theInactiveDragPict := GetPicture(129);
  184.     end; {InitMyWindow}
  185.     procedure DisposeMyWindow (varCode: integer; macWindow: WindowPeek);
  186.     begin
  187.         if HasCQDraw then
  188.             begin
  189.                 DisposeCIcon(MyDataHandle(macWindow^.dataHandle)^^.theCloseBoxCicn);
  190.                 DisposeCIcon(MyDataHandle(macWindow^.dataHandle)^^.theHitCloseBoxCicn);
  191.             end;
  192.         ReleaseResource(Handle(MyDataHandle(macWindow^.dataHandle)^^.theDragPict));
  193.         ReleaseResource(Handle(MyDataHandle(macWindow^.dataHandle)^^.theInactiveDragPict));
  194.     end; {DisposeMyWindow}
  195.  
  196. end.